import React from 'react';

import {Switch,Route,Redirect} from 'react-router-dom';

function RouterView({routerConfig}){ // /--->

    if(!routerConfig.length){
        return;
    }
    console.log(routerConfig);

    let redirectArr = routerConfig.filter(item => item.redirect);
    return <Switch>
        {
            routerConfig.map(item => {
                return item.component && item.path !== '*'? <Route key={item.path} path={item.path} render={(routerProps) => {
                    return <item.component {...routerProps} routerConfig={item.children}></item.component>
                }}></Route> : null;
            })
        }

        {
            redirectArr.map(item => {
                return <Redirect exact key={item.path} from={item.path} to={item.redirect}></Redirect> ;
            })
        }
        {
           <Route path="*" render={() => {
               return <div>汽车之家走丢了...</div>
           }}></Route> 
        }
    </Switch>
}

export default RouterView